﻿using ChessTest.Chess.Items;
using org.xisoft.game.utils.game;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ChessTest.Chess.Algorithms
{
    /// <summary>
    /// 带排序的alphabeta算法
    /// </summary>
    class SortedAlphaBetaAlgorithm : AlphaBetaAlgorithm
    {
        private int SortCompare(MoveAction l, MoveAction r)
        {
            long s = r.Score - l.Score;
            //杀子为第一优先级
            if (s != 0)
                return (int)s;

            int leftScore = l.CurrentChessman.Score;
            int rightScore = r.CurrentChessman.Score;
            if (l.CurrentChessman is KingItem)
                leftScore = 0;
            if (r.CurrentChessman is KingItem)
                rightScore = 0;
            
            //其次走子顺序为车马跑，
            return rightScore - leftScore;
        }

        public override List<MoveAction> GetAllCanMoves(AiChessboard aiChessboard)
        {
            List<MoveAction> list= base.GetAllCanMoves(aiChessboard);

            //杀子优先
            list.Sort((l, r) => SortCompare(l, r));
            return list;
        }


    }

}
